﻿/******************************************************************************
 *  All Rights Reserved , Copyright (C) 2012 , EricHu. 
 *  作    者： EricHu
 *  创建时间： 2012-7-20 16:35:48
 ******************************************************************************/
//--------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2012 , gt TECH, Ltd.
//--------------------------------------------------------------------

using System;
using System.Data;

namespace RDIFramework.BusinessEntity
{
  using RDIFramework.Utilities;

 /// <summary>
 /// CiItemsEntity
 /// 数据字典主表
 ///
 /// 修改纪录
 ///
 ///		2012-03-02 版本：1.0 EricHu 创建主键。
 ///
 /// 版本：1.0
 ///
 /// <author>
 ///		<name>EricHu</name>
 ///		<date>2012-03-02</date>
 /// </author>
 /// </summary>
    public partial class CiItemsEntity
    {

        #region 私有成员

        private bool _IsChanged;
        private bool _IsDeleted;
        private int? _Id;
        private string _Code;
        private string _Category;
        private string _FullName;
        private string _TargetTable;
        private int? _IsTree;
        private string _UseItemCode;
        private string _UseItemName;
        private string _UseItemValue;
        private int? _AllowEdit;
        private int? _AllowDelete;
        private int? _DeleteMark;
        private string _Description;
        private int? _Enabled;
        private int? _SortCode;
        private DateTime? _CreateOn;
        private string _CreateUserId;
        private string _CreateBy;
        private DateTime? _ModifiedOn;
        private string _ModifyUserId;
        private string _ModifiedBy; 
        #endregion
		
		#region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataRow">数据行</param>
        public CiItemsEntity(DataRow dataRow)
        {
            this.GetFrom(dataRow);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataReader">数据流</param>
        public CiItemsEntity(IDataReader dataReader)
        {
            this.GetFrom(dataReader);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataTable">数据表</param>
        public CiItemsEntity(DataTable dataTable)
        {
            this.GetFrom(dataTable);
        }

		/// <summary>
		/// 默认构造函数
		/// </summary>
        public CiItemsEntity()
		{
			_Id = 0; 
			_Code = null; 
			_FullName = null; 
			_TargetTable = null; 
			_IsTree =  null; 
			_UseItemCode = null; 
			_UseItemName = null; 
			_UseItemValue = null; 
			_AllowEdit = 1; 
			_AllowDelete = 1; 
			_DeleteMark = 0; 
			_Description = null; 
			_Enabled = 1; 
			_SortCode =  null;
            _CreateOn = DateTime.Now; 
			_CreateUserId = null; 
			_CreateBy = null;
            _ModifiedOn = DateTime.Now; 
			_ModifyUserId = null; 
			_ModifiedBy = null; 
		}
		#endregion

        #region 公有属性

        /// <summary>
        /// 主键
        /// </summary>		
        public virtual int? Id
        {
            get { return _Id; }
            set { _IsChanged |= (_Id != value); _Id = value; }
        }

        /// <summary>
        /// 编号
        /// </summary>		
        public virtual string Code
        {
            get { return _Code; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for Code", value, value.ToString());

                _IsChanged |= (_Code != value); _Code = value;
            }
        }

        /// <summary>
        /// 名称
        /// </summary>		
        public virtual string FullName
        {
            get { return _FullName; }
            set
            {
                if (value != null)
                    if (value.Length > 200)
                        throw new ArgumentOutOfRangeException("Invalid value for FullName", value, value.ToString());

                _IsChanged |= (_FullName != value); _FullName = value;
            }
        }

        /// <summary>
        /// 数据字典分类
        /// </summary>
        public virtual string Category
        {
            get { return _Category; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for Category", value, value.ToString());

                _IsChanged |= (_Category != value); _Category = value;
            }
        }

        /// <summary>
        /// 目标存储表
        /// </summary>		
        public virtual string TargetTable
        {
            get { return _TargetTable; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for TargetTable", value, value.ToString());

                _IsChanged |= (_TargetTable != value); _TargetTable = value;
            }
        }

        /// <summary>
        /// 树型结构
        /// </summary>		
        public virtual int? IsTree
        {
            get { return _IsTree; }
            set { _IsChanged |= (_IsTree != value); _IsTree = value; }
        }

        /// <summary>
        /// 编号字段对应值
        /// </summary>		
        public virtual string UseItemCode
        {
            get { return _UseItemCode; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for UseItemCode", value, value.ToString());

                _IsChanged |= (_UseItemCode != value); _UseItemCode = value;
            }
        }

        /// <summary>
        /// 名称字段对应值
        /// </summary>		
        public virtual string UseItemName
        {
            get { return _UseItemName; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for UseItemName", value, value.ToString());

                _IsChanged |= (_UseItemName != value); _UseItemName = value;
            }
        }

        /// <summary>
        /// 值字段对应值
        /// </summary>		
        public virtual string UseItemValue
        {
            get { return _UseItemValue; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for UseItemValue", value, value.ToString());

                _IsChanged |= (_UseItemValue != value); _UseItemValue = value;
            }
        }

        /// <summary>
        /// 允许编辑
        /// </summary>		
        public virtual int? AllowEdit
        {
            get { return _AllowEdit; }
            set { _IsChanged |= (_AllowEdit != value); _AllowEdit = value; }
        }

        /// <summary>
        /// 允许删除
        /// </summary>		
        public virtual int? AllowDelete
        {
            get { return _AllowDelete; }
            set { _IsChanged |= (_AllowDelete != value); _AllowDelete = value; }
        }

        /// <summary>
        /// 删除标记
        /// </summary>		
        public virtual int? DeleteMark
        {
            get { return _DeleteMark; }
            set { _IsChanged |= (_DeleteMark != value); _DeleteMark = value; }
        }

        /// <summary>
        /// 描述
        /// </summary>		
        public virtual string Description
        {
            get { return _Description; }
            set
            {
                if (value != null)
                    if (value.Length > 800)
                        throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());

                _IsChanged |= (_Description != value); _Description = value;
            }
        }

        /// <summary>
        /// 有效
        /// </summary>		
        public virtual int? Enabled
        {
            get { return _Enabled; }
            set { _IsChanged |= (_Enabled != value); _Enabled = value; }
        }

        /// <summary>
        /// 排序码
        /// </summary>		
        public virtual int? SortCode
        {
            get { return _SortCode; }
            set { _IsChanged |= (_SortCode != value); _SortCode = value; }
        }

        /// <summary>
        /// 创建日期
        /// </summary>		
        public virtual DateTime? CreateOn
        {
            get { return _CreateOn; }
            set { _IsChanged |= (_CreateOn != value); _CreateOn = value; }
        }

        /// <summary>
        /// 创建用户主键
        /// </summary>		
        public virtual string CreateUserId
        {
            get { return _CreateUserId; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for CreateUserId", value, value.ToString());

                _IsChanged |= (_CreateUserId != value); _CreateUserId = value;
            }
        }

        /// <summary>
        /// 创建用户
        /// </summary>		
        public virtual string CreateBy
        {
            get { return _CreateBy; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for CreateBy", value, value.ToString());

                _IsChanged |= (_CreateBy != value); _CreateBy = value;
            }
        }

        /// <summary>
        /// 修改日期
        /// </summary>		
        public virtual DateTime? ModifiedOn
        {
            get { return _ModifiedOn; }
            set { _IsChanged |= (_ModifiedOn != value); _ModifiedOn = value; }
        }

        /// <summary>
        /// 修改用户主键
        /// </summary>		
        public virtual string ModifyUserId
        {
            get { return _ModifyUserId; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for ModifyUserId", value, value.ToString());

                _IsChanged |= (_ModifyUserId != value); _ModifyUserId = value;
            }
        }

        /// <summary>
        /// 修改用户
        /// </summary>		
        public virtual string ModifiedBy
        {
            get { return _ModifiedBy; }
            set
            {
                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for ModifiedBy", value, value.ToString());

                _IsChanged |= (_ModifiedBy != value); _ModifiedBy = value;
            }
        }

        /// <summary>
        /// 对象的值是否被改变
        /// </summary>
        public virtual bool IsChanged
        {
            get { return _IsChanged; }
        }

        /// <summary>
        /// 对象是否已经被删除
        /// </summary>
        public virtual bool IsDeleted
        {
            get { return _IsDeleted; }
        }

        #endregion

        #region 公有函数

        /// <summary>
        /// 标记对象已删除
        /// </summary>
        public virtual void MarkAsDeleted()
        {
            _IsDeleted = true;
            _IsChanged = true;
        }


        #endregion

        #region 重写Equals和HashCode
        /// <summary>
        /// 用唯一值实现Equals
        /// </summary>
        public override bool Equals(object obj)
        {
            if (this == obj) return true;
            if ((obj == null) || (obj.GetType() != GetType())) return false;
            CiItemsEntity castObj = (CiItemsEntity)obj;
            return (castObj != null) &&
                (_Id == castObj.Id);
        }

        /// <summary>
        /// 用唯一值实现GetHashCode
        /// </summary>
        public override int GetHashCode()
        {
            int hash = 57;
            hash = 27 * hash * _Id.GetHashCode();
            return hash;
        }
        #endregion

        /// <summary>
        /// 从数据表读取
        /// </summary>
        /// <param name="dataTable">数据表</param>
        public virtual CiItemsEntity GetFrom(DataTable dataTable)
        {
            if ((dataTable == null) || (dataTable.Rows.Count == 0))
            {
                return null;
            }
            foreach (DataRow dataRow in dataTable.Rows)
            {
                this.GetFrom(dataRow);
                break;
            }
            return this;
        }

        /// <summary>
        /// 从数据行读取
        /// </summary>
        /// <param name="dataRow">数据行</param>
        public virtual CiItemsEntity GetFrom(DataRow dataRow)
        {
            this.Id = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldId]);
            this.Code = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldCode]);
            this.FullName = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldFullName]);
            this.Category = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldCategory]);
            this.TargetTable = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldTargetTable]);
            this.IsTree = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldIsTree]);
            this.UseItemCode = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldUseItemCode]);
            this.UseItemName = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldUseItemName]);
            this.UseItemValue = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldUseItemValue]);
            this.AllowEdit = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldAllowEdit]);
            this.AllowDelete = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldAllowDelete]);
            this.DeleteMark = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldDeleteMark]);
            this.Description = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldDescription]);
            this.Enabled = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldEnabled]);
            this.SortCode = BusinessLogic.ConvertToInt(dataRow[CiItemsTable.FieldSortCode]);
            this.CreateOn = BusinessLogic.ConvertToDateTime(dataRow[CiItemsTable.FieldCreateOn]);
            this.CreateUserId = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldCreateUserId]);
            this.CreateBy = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldCreateBy]);
            this.ModifiedOn = BusinessLogic.ConvertToDateTime(dataRow[CiItemsTable.FieldModifiedOn]);
            this.ModifyUserId = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldModifyUserId]);
            this.ModifiedBy = BusinessLogic.ConvertToString(dataRow[CiItemsTable.FieldModifiedBy]);
            return this;
        }

        /// <summary>
        /// 从数据流读取
        /// </summary>
        /// <param name="dataReader">数据流</param>
        public virtual CiItemsEntity GetFrom(IDataReader dataReader)
        {
            this.Id = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldId]);
            this.Code = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldCode]);
            this.FullName = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldFullName]);
            this.Category = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldCategory]);
            this.TargetTable = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldTargetTable]);
            this.IsTree = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldIsTree]);
            this.UseItemCode = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldUseItemCode]);
            this.UseItemName = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldUseItemName]);
            this.UseItemValue = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldUseItemValue]);
            this.AllowEdit = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldAllowEdit]);
            this.AllowDelete = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldAllowDelete]);
            this.DeleteMark = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldDeleteMark]);
            this.Description = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldDescription]);
            this.Enabled = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldEnabled]);
            this.SortCode = BusinessLogic.ConvertToInt(dataReader[CiItemsTable.FieldSortCode]);
            this.CreateOn = BusinessLogic.ConvertToDateTime(dataReader[CiItemsTable.FieldCreateOn]);
            this.CreateUserId = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldCreateUserId]);
            this.CreateBy = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldCreateBy]);
            this.ModifiedOn = BusinessLogic.ConvertToDateTime(dataReader[CiItemsTable.FieldModifiedOn]);
            this.ModifyUserId = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldModifyUserId]);
            this.ModifiedBy = BusinessLogic.ConvertToString(dataReader[CiItemsTable.FieldModifiedBy]);
            return this;
        }
    }
}
